//
//  UIButton+Extension.swift
//  0110-weibo
//
//  Created by 鲍志刚 on 16/1/16.
//  Copyright © 2016年 zhongye. All rights reserved.
//

import UIKit

extension UIButton {
    // 指定背景图片 和 按钮的图片的构造函数
    convenience init(imageName: String,backImageName: String) {
        self.init()
        setImage(UIImage(named: imageName), forState: .Normal)
        setImage(UIImage(named: imageName + "_highlighted"), forState: .Highlighted)
        setBackgroundImage(UIImage(named: backImageName), forState: .Normal)
        setBackgroundImage(UIImage(named: backImageName + "_highlighted"), forState: .Highlighted)
        
        //指定大小
        sizeToFit()
    }
    
    
    //
    convenience init(title: String, fontSize: CGFloat,color: UIColor,backImageName: String?, imageName: String? = nil) {
        self.init()
        //设置按钮的文字
        setTitle(title, forState: .Normal)
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
        setTitleColor(color, forState: .Normal)
        
        if backImageName != nil {
            
            setBackgroundImage(UIImage(named:backImageName!), forState: .Normal)
        }
        
        if imageName != nil {
            setImage(UIImage(named: imageName!), forState: .Normal)
            
        }
        
        sizeToFit()
    }
}